package com.echo.echovividlive.controller;


import com.echo.echovividlive.domain.dto.CommentQueryDTO;
import com.echo.echovividlive.domain.dto.FollowingVideosDTO;
import com.echo.echovividlive.domain.dto.PageQueryDTO;
import com.echo.echovividlive.domain.dto.VideoPageDTO;
import com.echo.echovividlive.domain.entity.Comment;
import com.echo.echovividlive.domain.entity.Result;
import com.echo.echovividlive.domain.entity.Video;
import com.echo.echovividlive.service.ICommentService;
import com.echo.echovividlive.service.IUserInteractService;
import com.echo.echovividlive.service.IVideoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiajunjie
 * @since 2024-10-22
 */
@Slf4j
@RestController
@RequestMapping("/echo/video")
@RequiredArgsConstructor
public class VideoController {

    private final IVideoService videoService;

    private final IUserInteractService userInteractService;

    private final ICommentService commentService;

    /**
     * 视频上传
     * @param video
     * @return
     * @throws FileNotFoundException
     */
    @PostMapping("/upload")
    public Result uploadVideo(@RequestParam("video") MultipartFile video) throws FileNotFoundException {
        return videoService.upload(video);
    }

    /**
     * 正式发布
     * @param video
     * @return
     */
    @PostMapping("/post")
    public Result postVideo(@RequestBody Video video){
      log.info("视频正式发布参数:{}",video);
      return videoService.post(video);
    }

    /**
     * 删除视频
     * @param video
     * @return
     */
    @PostMapping("/delete")
    public Result deleteVideo(@RequestBody Video video){
        log.info("删除视频参数:{}",video);
        return videoService.delete(video);
    }

    /**
     * 分页查询视频
     * @param pageQueryDTO
     * @return
     */
    @PostMapping("/list")
    public Result listVideo(@RequestBody VideoPageDTO pageQueryDTO){
        log.info("分页查询视频列表参数:{}",pageQueryDTO);
        return videoService.pageList(pageQueryDTO);
    }

    /**
     * 获取视频详情
     * @param videoId
     * @return
     */
    @GetMapping("/info/{videoId}")
    public Result getVideoInfo(@PathVariable("videoId") Integer videoId){
        return videoService.getVideo(videoId);
    }


    /**
     * 点赞视频
     * @param videoId
     * @return
     */
    @GetMapping("/like/{videoId}")
    public Result like(@PathVariable Integer videoId) {
        return userInteractService.like(videoId);
    }

//
//    /**
//     * 取消点赞
//     * @param videoId
//     * @return
//     */
//    @GetMapping("/cancelLike/{videoId}")
//    public Result cancelLike(@PathVariable Integer videoId) {
//        return userInteractService.cancelLike(videoId);
//    }



    /**
     * 获取关注视频
     * @param pageQueryDTO
     * @return
     */
    @PostMapping("/following/list")
    public Result followingVideo(@RequestBody FollowingVideosDTO pageQueryDTO) {
        log.info("获取关注视频参数:{}",pageQueryDTO);
        return videoService.getFollowingVideos(pageQueryDTO);
    }

    /**
     * 判断是否点赞
     * @param videoId
     * @return
     */
    @GetMapping("/isLike/{videoId}")
    public Result isVideoLike(@PathVariable Integer videoId) {
        return videoService.isVideoLike(videoId);
    }

    /**
     * 获取关注视频
     * @param pageQueryDTO
     * @return
     */
    @PostMapping("/like/list")
    public Result getVideoLikeList(@RequestBody VideoPageDTO pageQueryDTO) {
        return videoService.getLikedVideos(pageQueryDTO);
    }

    /**
     * 上传封面
     * @param cover
     * @return
     */
    @PostMapping("/cover")
    public Result coverVideo(@RequestParam("cover") MultipartFile cover) {
        return videoService.uploadCover(cover);
    }
}
